/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  dev
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

//                    x2     x3
//                    |      |
//                     inlet
//                    6 ____ 9 ---- y3
//                    |      |
//           ------>  |  b4  |
//           |        |      |
//           |      - 7 ____10 ---- y2
//           |     /  |      |
//   cylinderHead /   |  b3  | valveStem
//        0 ____ 1 b2 |      |
//        |      |  - 8_____11 ---- y4
//        |  b0  | /
//        |      |/  valveHead
// liner  2 ____ 3 ___________12 -- y0
//        |      |             |
//        |  b1  |     b5      | symmetry
//        |      |             |
//        4 ____ 5 ___________13 -- y1
//
//          ------ piston ------
//
//        |      |             |
//        x0     x1            x4
//

valveLift -2;
pistonPos -4;

cylinderWidth 26;
meshSecWidth  2;
valveStem     2;
valveHead     1;
spacing       1;
inletHeight   8;

// Vertical mesh density
nPiston 8;
nValve 8;
nInlet 24;

// Horizontal mesh density
nx0 4;
nx1 #calc "ceil(2.0*$nx0)";
nx2 #calc "ceil(3.75*$nx0)";

x0 #calc "(3.0*$meshSecWidth - $cylinderWidth) / 4.0";
x1 #calc "$x0 + $spacing";
x2 #calc "$x1 + $valveHead";
x3 #calc "-$valveStem / 2.0";
x4 0.0;

y0 $valveLift;
y1 $pistonPos;
y2 $valveHead;
y3 $inletHeight;
y4 #calc "$valveLift + $valveHead";

z0 0.0;
z1 0.5;

vertices
(
    ($x0 0.0 $z0) //0
    ($x1 0.0 $z0) //1
    ($x0 $y0 $z0) //2
    ($x1 $y0 $z0) //3
    ($x0 $y1 $z0) //4
    ($x1 $y1 $z0) //5
    ($x2 $y3 $z0) //6
    ($x2 $y2 $z0) //7
    ($x2 $y4 $z0) //8
    ($x3 $y3 $z0) //9
    ($x3 $y2 $z0) //10
    ($x3 $y4 $z0) //11
    ($x4 $y0 $z0) //12
    ($x4 $y1 $z0) //13

    ($x0 0.0 $z1) //14
    ($x1 0.0 $z1) //15
    ($x0 $y0 $z1) //16
    ($x1 $y0 $z1) //17
    ($x0 $y1 $z1) //18
    ($x1 $y1 $z1) //19
    ($x2 $y3 $z1) //20
    ($x2 $y2 $z1) //21
    ($x2 $y4 $z1) //22
    ($x3 $y3 $z1) //23
    ($x3 $y2 $z1) //24
    ($x3 $y4 $z1) //25
    ($x4 $y0 $z1) //26
    ($x4 $y1 $z1) //27
);

blocks
(
    hex (0 2 3 1 14 16 17 15) ($nValve $nx0 1) simpleGrading (1 1 1)
    hex (2 4 5 3 16 18 19 17) ($nPiston $nx0 1) simpleGrading (1 1 1)
    hex (1 3 8 7 15 17 22 21) ($nValve $nx0 1) simpleGrading (1 1 1)
    hex (7 8 11 10 21 22 25 24) ($nValve $nx1 1) simpleGrading (1 1 1)
    hex (6 7 10 9 20 21 24 23) ($nInlet $nx1 1) simpleGrading (1 1 1)
    hex (3 5 13 12 17 19 27 26) ($nPiston $nx2 1) simpleGrading (1 1 1)
);

defaultPatch
{
    name    frontAndBack;
    type    empty;
}

boundary
(
    piston
    {
        type    wall;
        faces
        (
            (4 5 18 19)
            (5 13 19 27)
        );
    }

    liner
    {
        type    wall;
        faces
        (
            (4 2 18 16)
            (2 0 16 14)
        );
    }

    cylinderHead
    {
        type    wall;
        faces
        (
            (0 1 15 14)
            (1 7 21 15)
            (7 6 20 21)
        );
    }

    inlet
    {
        type    patch;
        faces
        (
            (6 9 23 20)
        );
    }

    valveHead
    {
        type    wall;
        faces
        (
            (8 11 25 22)
            (3 8 22 17)
            (12 3 17 26)
        );
    }

    valveStem
    {
        type    wall;
        faces
        (
            (9 10 24 23)
            (10 11 25 24)
        );
    }

    symmetry
    {
        type    patch;
        faces
        (
            (13 27 26 12)
        );
    }
);

// ************************************************************************* //
